

class Res1{
        public String userSex;
        public String userName;
        public boolean flag=false;
}

class IntThrad1 extends Thread {
    private Res1 res;

    public IntThrad1(Res1 res) {
        this.res = res;
    }

    @Override
    public void run() {
        int count = 0;
        while (true) {
            synchronized (res){
                if(res.flag){
                    try {
                        res.wait();
                    }catch (Exception e){

                    }
                }
                if (count == 0) {
                    res.userName = "余胜军";
                    res.userSex = "男";
                } else {
                    res.userName = "小紅";
                    res.userSex = "女";
                }
                count = (count + 1) % 2;
                res.flag=true;
                res.notify();
            }
        }
    }
}

class OutThread1 extends Thread {
    private Res1 res;

    public OutThread1(Res1 res) {
        this.res = res;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (res){
                if(!res.flag){
                    try {
                        res.wait();
                    }catch (Exception e){

                    }
                }
                System.out.println(res.userName + "--" + res.userSex);
                res.flag=false;
                res.notify();
            }
        }
    }
}


public class Test003 {

    public static void main(String[] args){
        Res1 res=new Res1();
        IntThrad1 intThrad=new IntThrad1(res);
        OutThread1 outThread=new OutThread1(res);
        intThrad.start();
        outThread.start();
    }
}
